<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>无标题文档</title>
    <link href="../../../static/css/style.css" rel="stylesheet" type="text/css"/>
</head>

<body>
<div class="place"><span>位置：</span>
    <ul class="placeul">
        <li>仓库管理</li>
        <li>入库管理</li>
        <li>添加入库</li>
    </ul>
</div>
<div class="formbody">
    <div class="formtitle"><span>入库信息</span></div>
    <ul class="forminfo">
        <li>
            <label>采购单编号</label>
            <input maxlength="50" id="indent" type="text" class="dfinput" onblur="state()"/>
            <!--            onfocus="updateAlert()"-->
            <a href="" title="点击查看采购单详细信息" class="tablelink">详情</a>
            <i id="alert">必须是审核通过的采购单</i>
        </li>
        <li>
            <label>入库</label>
            <select id="cName" class="dfselect">
                <!--          <option>请选择</option>-->
                <!--          <option>南京21号仓库</option>-->
                <!--          <option>武汉71号仓库</option>-->
                <!--          <option>天津83号仓库</option>-->
            </select>
            <i>必选</i>
        </li>
        <li>
            <label>入库时间</label>
            <input name="" id="time1" type="date" class="dfinput"/> <input name="" id="time2" type="time"
                                                                           class="dfinput"/>
            <i>必填</i>
        </li>
        <li>
            <label>出库人</label>
            <input name="" type="text" value="马云" id="users" readonly="readonly" class="roinput"/>
            <i>不能编辑</i>
        <li>
            <label>&nbsp;</label>
            <input name="" type="button" onclick="submitMessage()" class="btn" value="确认"/>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <a href="/rkWarehouse/lists"><input name="" type="button" class="btn" value="返回"/></a>
        </li>
    </ul>
</div>
<script type="text/javascript" src="../../../static/js/jquery.js"></script>
<script>
    loadstorage()

    //加载仓库列表,用户

    function loadstorage() {
        $.ajax({
            url: "/Warehouse/WarehouseList",
            type: "get",
            dataType: "json",
            success: (pb) => {
                let store = new Array();
                store = pb.data;
                $("#cName").html('')
                store.forEach((item, index) => {
                    $("#cName").append(`<option name="${item.id}" value="${item.id}">${item.cname}</option>`)
                })
            }
        })
        var nowUser = JSON.parse(localStorage.getItem("user"));//当前用户
        $('#users').val(nowUser.uname);
    }

    //失去焦点判断采购单状态
    function state() {
        $.ajax({
            url: "/InWarehouse/queryPurchaseState",
            type: "get",
            data: {
                indent: $('#indent').val()
            },
            dataType: "json",
            success: (pb) => {
                // alert(pb.data.cgState)
                // alert(pb.data.checkStatus)
                    if (pb.data != "") {
                        if (pb.data.cgState == 2) {
                            if (pb.data.checkStatus == 1) {
                                $('#indent').focus();
                                $('#alert').html("该采购单未审核!")
                            }
                            if (pb.data.checkStatus == 2) {
                                $('#indent').focus();
                                $('#alert').html("该采购单在审核中!")
                            }
                            if (pb.data.checkStatus == 3) {
                                // $('#indent').focus();
                                $('#alert').html("该采购单已审核通过!")
                            }
                            if (pb.data.checkStatus == 4) {
                                $('#indent').focus();
                                $('#alert').html("该采购单审核未通过!")
                            }

                        } else if (pb.data.cgState == 1) {
                            $('#indent').focus();
                            $('#alert').html("该采购单已入库!")
                        }
                    } else {
                        $('#indent').focus();
                        $('#alert').html("采购单不存在!")
                    }
            }
        })
    }

    // function updateAlert() {
    //     $('#alert').html("必须是审核通过的采购单!")
    // }

    //添加入库
    function submitMessage() {
        var nowUser = JSON.parse(localStorage.getItem("user"));//当前用户
        $('#users').val(nowUser.uname);
        let nowUserID = nowUser.uid;

        // alert($('#indent').val())
        // alert($('#cName:selected').attr('name'))
        // alert($('#time1').val()+' '+$('#time2').val()+':00')   //2022-11-04 18:40  yyyy-MM-dd HH:mm:ss
        // alert(nowUserID)

        $.ajax({
            url: "/InWarehouse/InWarehouseAdd",
            type: "get",
            dataType: "json",
            data: {
                indent: $('#indent').val(),//采购单ID
                WarehouseID: $("#cName option:selected").attr("name"),
                inTime: $('#time1').val() + ' ' + $('#time2').val() + ':00',  //2022-11-04 18:40  yyyy-MM-dd HH:mm:ss
                userID: nowUserID
            },
            success: (data) => {
                // $("#users").html(data);
                alert(data.msg);
            }
        })
    }
</script>
</body>
</html>
